package main

import (
	"fmt"
	"os"
)

func main() {
	f, err := os.Open("test.txt")
	if err != nil {
		//log.Fatal(err) //The system cannot find the file specified.
		//相当于下面的两行代码
		//fmt.Println(err)
		//return
		fmt.Println(err)
		if ins, ok := err.(*os.PathError); ok {
			fmt.Println("1.Op:", ins.Op)     //1.Op: open
			fmt.Println("2.Path:", ins.Path) //2.Path: test.txt
			fmt.Println("3.Err:", ins.Err)   //3.Err: The system cannot find the file specified.
		}
		return
	}
	fmt.Println(f.Name(), "打开文件成功。。")
}
